#include <iostream>
#include <type_traits>
#include <string>

#ifdef __linux__
#include <unistd.h>
#include <sys/socket.h>
#define closesocket close
#endif

#ifdef _WIN32
#include <winsock2.h>
using socket_t = SOCKET;
#else
using socket_t = int;
#endif

template<typename T>
void process(T value) 
{
    if constexpr (std::is_pointer_v<T> && !std::is_same_v<T, const char*>) 
    {
        // 指针类型的处理（排除const char*）
        std::cout << "Processing pointer: " << *value << std::endl;
    } 
    else if constexpr (std::is_integral_v<T>) 
    {
        // 整数类型的处理
        std::cout << "Processing integer: " << value * 2 << std::endl;
    } 
    else if constexpr (std::is_floating_point_v<T>) 
    {
        // 浮点类型的处理
        std::cout << "Processing float: " << value / 2.0 << std::endl;
    } 
    else if constexpr (std::is_same_v<T, const char*>)
    {
        // 字符串字面值的特殊处理
        std::cout << "Processing string: " << value << std::endl;
    }
    else
    {
        // 默认处理
        std::cout << "Processing unknown type" << std::endl;
    }
}

template<typename T>
void close_handle(T handle) {
    if constexpr (std::is_same_v<T, socket_t>) {
        closesocket(handle);
    } 
    else{
        close(handle);
    }
} 

int main()
{
    int i = 42;
    process(i);         // Processing integer: 84
    process(&i);        // Processing pointer: 42
    process(3.14);      // Processing float: 1.57
    process("hello");   // Processing string: hello
    
    return 0;
}





	
